package com.utonw.carloan.activity.main;


import android.Manifest;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.utonw.carloan.R;
import com.utonw.carloan.activity.base.BaseActivity;
import com.utonw.carloan.global.Constants;
import com.utonw.carloan.global.InitData;
import com.zhy.m.permission.MPermissions;
import com.zhy.m.permission.PermissionDenied;
import com.zhy.m.permission.PermissionGrant;

public class MainActivity extends BaseActivity {
    //首页功能列表，不同权限看到可能不同
    private RecyclerView mGuideView;

    @Override
    public void initView() {
        mGuideView = (RecyclerView) findViewById(R.id.rv_main_guide);
    }

    @Override
    public void initData() {
        //显示ToolBar右侧小人图标
        isShowConfig=true;

        //初始化核心控制器
        InitData initData = new InitData(this);
        //初始化下方多重function列表区
        initData.initComplexChooseBar();
        //初始化上方导航列表
        initData.initGuideRecyclerView(mGuideView, Constants.THEME_ORANGE);

        //动态权限获取
        MPermissions.requestPermissions(this, Constants.APPLY_PERMISSION, Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA);


    }


    @Override
    public int setLayout() {
        return R.layout.activity_main;
    }

    @Override
    public String setTitle() {
        return getString(R.string.main_title);
    }

    @Override
    public void initActionBar() {
        super.initActionBar();
        //设置ToolBar左上按钮监听
        mToggle = new ActionBarDrawerToggle(this, mMyDrawable, mTbHeadBar, R.string.drawer_open, R.string.drawer_close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);

            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);

            }
        };
        mToggle.syncState();
        mMyDrawable.addDrawerListener(mToggle);
    }



    //获取权限回调
    @PermissionGrant(Constants.APPLY_PERMISSION)
    public void requestContactSuccess() {

    }

    @PermissionDenied(Constants.APPLY_PERMISSION)
    public void requestContactFailed() {
        killAll();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        MPermissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

}
